package interfaceGrafica;

import java.io.File;
import javax.sound.sampled.*;

public class Som {

	private AudioInputStream audio;
	private Clip clip;

	public Som(String diretorio) {
		try {
			this.audio = AudioSystem.getAudioInputStream(new File(diretorio));
			this.clip = AudioSystem.getClip();
			this.clip.open(audio);
			this.clip.start();

		} catch (Exception e) {
			System.out.println("Erro leitura de arquivo");
		}
	}

	public void loop(boolean repetir) {
		if (repetir == true) {
			this.clip.loop(Clip.LOOP_CONTINUOUSLY);
		} else {
			this.clip.loop(0);
		}
	}

	public void play() {
		this.clip.start();
	}

	public void stop() {
		this.clip.loop(0);
		this.clip.stop();
		this.clip.setFramePosition(0);
	}

	public void pause() {
		this.clip.stop();
	}
}
